function [fun, grad] = PL_penalty(method, beta, varargin)
% [fun, grad] = PL_penalty(method, beta, varargin)
% 
% PL_penalty is a wrapper function for several penalty / regularization 
% terms. These include Parallel Level Sets [1], Colour Total Variation [2]
% and the Nambu functional [3].
% Next to the function values also the gradient is computed.
%
% See also: PL_penalty_parallel, PL_penalty_CTV, PL_penalty_Nambu 
%
% [1] M. J. Ehrhardt and S. Arridge, 
%     Vector-Valued Image Processing by Parallel Level Sets, 
%     IEEE Transactions on Image Processing (to appear), 2013
% [2] P. Blomgren and T. F. Chan, 
%     Color TV: Total Variation Methods for Restoration of Vector-Valued Images,
%     IEEE Transactions on Image Processing, vol. 7, no. 3, pp. 304–309, 1998
% [3] N. Sochen, R. Kimmel, and R. Malladi, 
%     A General Framework for Low Level Vision,
%     IEEE Transactions on Image Processing, vol. 7, no. 3, pp. 310–318, 1998
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------

    if iscell(varargin{1})
        input = varargin{1};
    else
        input = varargin;
    end
    
    if nargout > 1
        switch method
            case {'PL'}
                [fun, grad] = PL_penalty_parallel(beta, input);

            case {'CTV'}
                [fun, grad] = PL_penalty_CTV(beta, input);
    
            case {'Nambu'}
                [fun, grad] = PL_penalty_Nambu(beta, input);

            otherwise
                error('Method not defined.');
        end
    else
        switch method
            case {'PL'}
                fun = PL_penalty_parallel(beta, input);

            case {'CTV'}
                fun = PL_penalty_CTV(beta, input);
     
            case {'Nambu'}
                fun = PL_penalty_Nambu(beta, input);                

            otherwise
                error('Method not defined.');
        end
    end
end